package Interface;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;


public class CreateOccasionalOrder extends JFrame implements ActionListener {

	private  JLabel  lblCusName,lblCarId, lblLivingT, lblMail; 
	private JTextField  txtCusName, txtCarId, txtMail;
	private JButton btnBackToMenu, btnNext;
	
	Calendar calendar = Calendar.getInstance();
    Date earliestDate = calendar.getTime();
	Date d = new Date();
	private JSpinner spinner= new JSpinner();
	SpinnerDateModel model = new SpinnerDateModel(earliestDate,null,null,Calendar.HOUR);
	
	public CreateOccasionalOrder() {
		setTitle("Create New Parking Order");
		this.setSize(436, 286);
		this.getContentPane().setLayout(null);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	//	this.getContentPane().setBackground(Color.LIGHT_GRAY);

		model.setCalendarField(Calendar.MINUTE);
		spinner.setModel(model);
		spinner.setEditor(new JSpinner.DateEditor(spinner, "h:mm a"));
		spinner.setBounds(117, 106, 110, 25);
		getContentPane().add(spinner);
		
		
		btnBackToMenu = new JButton("Back To Menu");
		btnBackToMenu.setBounds(45, 215, 115, 25);
		getContentPane().add(btnBackToMenu);
		btnBackToMenu.addActionListener(this);
		
		btnNext = new JButton("Next");
		btnNext.setBounds(283, 215, 115, 25);
		getContentPane().add(btnNext);
		btnNext.addActionListener(this);
		
		
		lblCarId = new JLabel("Car ID:");
		lblCarId.setBounds(10, 41, 75, 25);
		getContentPane().add(lblCarId);
		
		lblCusName = new JLabel("Customer Name:");
		lblCusName.setBounds(10, 10, 97, 25);
		getContentPane().add(lblCusName);
		
		lblLivingT = new JLabel("Living Time");
		lblLivingT.setBounds(10, 106, 97, 25);
		getContentPane().add(lblLivingT);
		
		lblMail = new JLabel("E-Mail");
		lblMail.setBounds(10, 77, 97, 25);
		getContentPane().add(lblMail);
		
		txtCusName = new JTextField();
		txtCusName.setBounds(117, 12, 120, 20);
		getContentPane().add(txtCusName);
		
		txtCarId = new JTextField();
		txtCarId.setBounds(117, 43, 120, 20);
		getContentPane().add(txtCarId);
		
		txtMail = new JTextField();
		txtMail.setBounds(117, 74, 120, 20);
		getContentPane().add(txtMail);

		this.setVisible(true);
		
	}

	/*public void validateInput() {
	}

	public void sendMessageForOneTimeOrder() {
	}

	public void sendPayment() {
	}*/

	@Override
	public void actionPerformed(ActionEvent e) {
		Date date = (Date)spinner.getValue();
		   Calendar c = Calendar.getInstance(); 
		   c.setTime(date);
		   c.get(Calendar.HOUR);
		   c.get(Calendar.MINUTE);
		   
		   Calendar calendar1 = GregorianCalendar.getInstance(); 
		   calendar1.setTime(d);   
		   int time = calendar1.get(Calendar.HOUR);
		   
 		if(e.getSource() == btnNext)
		{
		if(c.get(Calendar.HOUR)>time)
		 {
			this.setVisible(false);
			JOptionPane.showMessageDialog(this,"Checkin was successful","OK",JOptionPane.INFORMATION_MESSAGE);
		}
		else
			JOptionPane.showMessageDialog(this,"Please enter correct time","Error",JOptionPane.ERROR_MESSAGE);
		}
		
		if(e.getSource() == btnBackToMenu)
		{
			this.setVisible(false);
			new KioskGui();
		}
			
		
	}
}
